//
//  RecommendViewController.m
//  wifi4.2
//
//  Created by 郭四虎 on 15/11/12.
//  Copyright © 2015年 YouKu. All rights reserved.
//

#import "RecommendViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>

#define URLstr @"http://tbs.iucool.cn:8080/cooba/cooba.html"
#define MYtitle @"知行安徽：以知为行，知决定行"
@interface RecommendViewController ()
{
    UIImage *_shareImage;
    UIImage *_launchImage;
}

@end

@implementation RecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"推荐给好友";
    
    getLaunchImage(_launchImage);
    
    CGRect rect = CGRectMake(WIDTH/2-SCALEY*90, 130*SCALEY, SCALEY*180, SCALEY*180);
    _shareImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(_launchImage.CGImage, rect)];
    
    //getNewImageWithRect(ima, _shareImage, CGSizeMake(100, 100));
}
- (IBAction)recommendClick:(UIButton *)sender {
    switch (sender.tag) {
        case 100:
        {//朋友圈
            NSMutableDictionary *para = [NSMutableDictionary dictionary];
            
            [para SSDKSetupWeChatParamsByText:@"" title:MYtitle url:[NSURL URLWithString:URLstr] thumbImage:nil image:_shareImage musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatTimeline];// 微信好友子平台
            
            [self.view Loading_0314];
            [ShareSDK share:SSDKPlatformSubTypeWechatTimeline parameters:para onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                
                switch (state) {
                    case SSDKResponseStateSuccess:
                    {
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享成功" afterDelay:0.5];
                        NSLog(@"success");
                    }
                        break;
                    case SSDKResponseStateFail:
                    {
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享失败" afterDelay:0.5];
                        NSLog(@"fail");
                    }
                        break;
                    case SSDKResponseStateCancel:
                    {
                        [self.view Hidden];
                        NSLog(@"cancel");
                    }
                        break;
                    default:
                        break;
                }
            }];
            break;
        }
        case 101:
        {//微信
            NSMutableDictionary *para = [NSMutableDictionary dictionary];
            
            [para SSDKSetupWeChatParamsByText:@"" title:MYtitle url:[NSURL URLWithString:URLstr] thumbImage:nil image:_shareImage musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatSession];// 微信好友子平台

            
            [ShareSDK share:SSDKPlatformSubTypeWechatSession parameters:para onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                
                switch (state) {
                    case SSDKResponseStateSuccess:
                    {
                        NSLog(@"success");
                    }
                        break;
                    case SSDKResponseStateFail:
                    {
                        NSLog(@"fail");
                    }
                        break;
                    case SSDKResponseStateCancel:
                    {
                        NSLog(@"cancel");
                    }
                        break;
                    default:
                        break;
                }
            }];

            break;
        }
        case 102:
        {//QQ
            NSMutableDictionary *para = [NSMutableDictionary dictionary];
            
            [para SSDKSetupQQParamsByText:@"" title:MYtitle url:[NSURL URLWithString:URLstr] thumbImage:nil image:_shareImage type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeQQFriend];
//            [para SSDKSetupWeChatParamsByText:@"分享内容" title:@"title" url:[NSURL URLWithString:@"http://baidu.com"] thumbImage:nil image:[UIImage imageNamed:@"图片.jpg"] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatSession];
            
            
            [ShareSDK share:SSDKPlatformSubTypeQQFriend parameters:para onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                
                switch (state) {
                    case SSDKResponseStateSuccess:
                    {
                        NSLog(@"success");
                    }
                        break;
                    case SSDKResponseStateFail:
                    {
                        NSLog(@"fail");
                    }
                        break;
                    case SSDKResponseStateCancel:
                    {
                        NSLog(@"cancel");
                    }
                        break;
                    default:
                        break;
                }
            }];
            
            break;
        }
        case 103:
        {//QQ空间
            NSMutableDictionary *para = [NSMutableDictionary dictionary];
            
            [para SSDKSetupQQParamsByText:@"" title:MYtitle url:[NSURL URLWithString:URLstr] thumbImage:nil image:_shareImage type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeQZone];
            
            [self.view Loading_0314];
            [ShareSDK share:SSDKPlatformSubTypeQZone parameters:para onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                
                switch (state) {
                    case SSDKResponseStateSuccess:
                    {
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享成功" afterDelay:0.5];
                        NSLog(@"success");
                    }
                        break;
                    case SSDKResponseStateFail:
                    {
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享失败" afterDelay:0.5];
                        NSLog(@"fail");
                    }
                        break;
                    case SSDKResponseStateCancel:
                    {
                        [self.view Hidden];
                        NSLog(@"cancel");
                    }
                        break;
                    default:
                        break;
                }
            }];

            
            break;
        }
        case 104:
        {//新浪微博
            CGRect rect = CGRectMake(WIDTH/2-SCALEY*90, 0, SCALEY*180, HEIGHT-100);
            UIImage *ima = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(_launchImage.CGImage, rect)];
            
            NSMutableDictionary *para = [NSMutableDictionary dictionary];
        
            [para SSDKSetupShareParamsByText:[NSString stringWithFormat:@"来看看吧%@",URLstr] images:ima url:[NSURL URLWithString:URLstr] title:MYtitle type:SSDKContentTypeAuto];
            
            [self.view Loading_0314];
            [ShareSDK showShareEditor:SSDKPlatformTypeSinaWeibo otherPlatformTypes:@[ @(SSDKPlatformSubTypeWechatTimeline)] shareParams:para onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                
                
                switch (state) {
                    case SSDKResponseStateSuccess:{
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享成功" afterDelay:0.5];
                        NSLog(@"success");
                    }
                        break;
                    case SSDKResponseStateFail:{
                        [self.view Hidden];
                        [self performSelector:@selector(showMsg:) withObject:@"分享失败" afterDelay:0.5];
                        NSLog(@"fail");
                    }
                        break;
                    case SSDKResponseStateCancel:{
                        [self.view Hidden];
                        NSLog(@"cancel");
                    }
                        break;
                    default:
                        break;
                }
                        
            }];

        }
        default:
            break;
    }
}
- (void)showMsg:(NSString *)msg
{
    [self.view Message:msg HiddenAfterDelay:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
